package com.example.demo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.ArrayAdapter;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.ViewSwitcher;

public class demoMainActivity extends AppCompatActivity {

    private SeekBar seekBar1;
    private RatingBar ratingBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo_main);
        String[] ctype1 = new String[]{"全部","美术","体育","检测"};

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,ctype1);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        Spinner sp = (Spinner)findViewById(R.id.spinn);
        sp.setAdapter(adapter);
        String st = sp.getSelectedItem().toString();
        Toast.makeText(this, st, Toast.LENGTH_SHORT).show();

        ImageSwitcher is = (ImageSwitcher)findViewById(R.id.image2);
        is.setOutAnimation(AnimationUtils.loadAnimation(demoMainActivity.this,android.R.anim.fade_out));
        is.setInAnimation(AnimationUtils.loadAnimation(demoMainActivity.this,android.R.anim.fade_in));

        is.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                ImageView imageview = new ImageView(demoMainActivity.this);
                imageview.setImageResource(R.drawable.img01);
                return imageview;

            }
        });

        is.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ((ImageSwitcher)v).setImageResource(R.drawable.img03);
            }
        });




        ratingBar = (RatingBar)findViewById(R.id.dratingbar);
        String rating = String.valueOf(ratingBar.getRating());
        Toast.makeText(this, "rating:"+rating, Toast.LENGTH_SHORT).show();
        String rating1 = String.valueOf(ratingBar.getNumStars());
        Toast.makeText(this, "总"+rating1, Toast.LENGTH_SHORT).show();
        String rating2 = String.valueOf(ratingBar.getProgress());
        Toast.makeText(this, "progress:"+rating2, Toast.LENGTH_SHORT).show();


        seekBar1 = (SeekBar)findViewById(R.id.seekbar1);

        seekBar1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                Toast.makeText(demoMainActivity.this, "亮度："+progress, Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                Toast.makeText(demoMainActivity.this, "开始", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                Toast.makeText(demoMainActivity.this, "结束", Toast.LENGTH_SHORT).show();
            }
        });

    }
}
